package com.tio.showcase.handler;

import com.tio.showcase.common.ShowcasePacket;
import com.tio.showcase.common.ShowcaseSessionContext;
import com.tio.showcase.packet.LoginResbody;
import com.tio.showcase.showcaseintf.AbsShowcaseBsHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;
import org.tio.utils.json.Json;

/**
 * Author      : liyuemin
 * Time        : 2017/12/15 16:18
 * Description :
 */
public class LoginRespHandler extends AbsShowcaseBsHandler<LoginResbody> {

    private Logger logger  = LoggerFactory.getLogger(LoginRespHandler.class);

    public Class<LoginResbody> bodyClass() {
        return LoginResbody.class;
    }

    public Object handle(ShowcasePacket showcasePacket, LoginResbody bsBody, ChannelContext channelContext) throws Exception {
        System.out.println("收到登陆响应消息："+ Json.toJson(bsBody));
        if(LoginResbody.Code.SUCCESS.equals(bsBody.getCode())){
            ShowcaseSessionContext showcaseSessionContext = (ShowcaseSessionContext) channelContext.getAttribute();
            showcaseSessionContext.setToken(bsBody.getToken());
            System.out.println("登陆成功，token是："+ bsBody.getToken());
        }
        return null;
    }
}
